<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>票据管理系统</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
    <style>
        .loginBtn {
            margin-top: 20px;
            color: #fff;
            font-size: 18px
        }

        .loginBtn > div {
            width: 100%;
            height: 40px;
            text-align: center;
            border-radius: 6px;
            background: #53d192;
            border: none;
            color: #fff;
            font-size: 18px;
            line-height: 40px;
            margin-top: 20px;
        }
    </style>
</head>

<body data-type="login">

<div class="am-g myapp-login">
    <div class="myapp-login-logo-block  tpl-login-max">
        <div class="myapp-login-logo-text">
            <div class="myapp-login-logo-text">
                票据管理系统
            </div>
        </div>
        <div class="am-u-sm-10 login-am-center">
            <form class="am-form">
                <fieldset>
                    <div id="login">
                        <div class="am-form-group">
                            <input type="email" v-model="user.account" id="doc-ipt-email-1" placeholder="请输入账号">
                        </div>
                        <div class="am-form-group">
                            <input type="password" v-model="user.password" id="doc-ipt-pwd-1" placeholder="请输入密码">
                        </div>
                        <div id="submit">
                            <a id="submitBtn" class="loginBtn" @click.prevent="reWeb">
                                <div>登 录</div>
                            </a>
                        </div>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
</div>

</body>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/app.js"></script>
<script src="assets/js/vue.js"></script>
<script src="assets/js/axios.min.js"></script>
<script>
    const userLogin = new Vue({
        el: "#login",
        data: {
            user: {
                account: "",
                password: "",
            },
            flag: false,
            enterpriseId: "",
            userName:"",
        },
        methods: {
            reWeb() {
                let _this = this;
                let formData = new FormData();
                formData.append("account", userLogin.user.account);
                formData.append("password", userLogin.user.password);
                axios({
                    method: "POST",
                    url: "admin/login.do",
                    data: formData,
                }).then(function (res) {
                    if (res.data.code === 200) {
                        alert("登录成功!");
                        axios.get("admin/findEnterpriseId.do?account=" + userLogin.user.account).then(
                            function (res) {
                                userLogin.enterpriseId = res.data.value;
                                console.log("企业id："+userLogin.enterpriseId);
                                window.sessionStorage.setItem("loginEnterpriseId", JSON.stringify(userLogin.enterpriseId));
                            }
                        );
                        axios.get("admin/getUserName.do?account=" + userLogin.user.account).then(
                            function(res) {
                                userLogin.userName = res.data.value;
                                console.log("登录名称："+userLogin.userName);
                                window.sessionStorage.setItem("userName", JSON.stringify(userLogin.userName));
                                location.href="transfer-list.html";
                            }
                        );
                    }
                    if (res.data.code === 201) {
                        alert("密码错误！登录失败");
                        _this.user.password="";
                    }
                    if (res.data.code === 202) {
                        alert("用户名不能为空！请输入账号...");
                    }
                    if (res.data.code === 203) {
                        alert("密码不能为空！请输入密码...");
                    }
                    if (res.data.code === 204) {
                        alert("用户名不存在！请重试...");
                    }
                });
            }
        },
        // created(){
        //     this.enterpriseId = null;
        //     console.log("企业id："+ this.enterpriseId)
        // },
    });

    // $(function () {
    //     $('#submitBtn').on('click', function () {
    //         let formData = new FormData();
    //         formData.append("account", userLogin.user.account);
    //         formData.append("password", userLogin.user.password);
    //         axios({
    //             method: "POST",
    //             url: "admin/login.do",
    //             data: formData,
    //         }).then(function (res) {
    //             if (res.data.code === 200) {
    //                 alert("登录成功!");
    //                 axios.get("admin/findEnterpriseId.do?account=" + userLogin.user.account).then(
    //                     function (res) {
    //                         userLogin.enterpriseId = res.data.value;
    //                         console.log( userLogin.enterpriseId);
    //                         const submitButton = new Vue({
    //                             el : "#submit",
    //                             data : {
    //                                 enterpriseId : userLogin.enterpriseId,
    //                             },
    //                             methods : {
    //                                 reWeb(){
    //                                     alert("1111")
    //                                     // location.href="transfer-list.html?enterpriseId="+this.enterpriseId
    //                                 },
    //                             }
    //                         })
    //                     }
    //                 )
    //             }
    //             if (res.data.code === 201) {
    //                 alert("密码错误！登录失败");
    //             }
    //             if (res.data.code === 202) {
    //                 alert("用户名不能为空！请输入账号...");
    //             }
    //             if (res.data.code === 203) {
    //                 alert("密码不能为空！请输入密码...");
    //             }
    //             if (res.data.code === 204) {
    //                 alert("用户名不存在！请重试...");
    //             }
    //         })
    //     });
    // });

</script>
</html>